import { Request, Response, NextFunction } from "express";
import { connection } from "@/services/database";
import { generateInsertFields } from "@/utils/sql";
import { createRandomNumber } from "@/utils/random";

interface Params {
	user_id: number;
	parent_phone_number: string;
	origin: string;
	party_affiliation: "中共党员/预备党员" | "共青团员" | "群众";
	major: string;
	awards?: string;
	personal_evaluation?: string;
	personal_intentions?: string;
}
export default async (request: Request, response: Response, next: NextFunction) => {
	try {
		const params = request.body as unknown as Params;
		const signup_id = createRandomNumber(8);
		(await connection.execute("INSERT INTO signup " + generateInsertFields({ signup_id, ...params }), { signup_id, ...params })) as any;
		response.json({ data: null, message: "成功" });
	} catch (error) {
		response.statusCode = 400;
		next(error);
	}
};
